// 02local/06selectDesk/selectDesk.js
var co = require('../../resource/js/common.js')
var app = getApp()
var _this
Page({
    data: {
        tableList: null,    //餐桌列表
        //获取传递的商家ID和用餐人数 
        Biz_ID: '',
        num: '',
        value: ''
    },
    onLoad: function (options) {
        _this = this
        // 存入data
        this.setData({
            Biz_ID: options.Biz_ID,
            num: options.Guest_Num,
            value: options.value
        })
        // 获取餐桌信息
        this.getTableList()
    },
    // 获取餐桌信息
    getTableList: function () {
        var param = {
            // this.data.Biz_ID
            Biz_ID: 75,
            Guest_Num: this.data.num
        }
        co.getMealApi('table/Tmg/selectTheBestTable', param, function (res) {
            // console.log('【返回餐桌信息】===', res)
            if (res.code == 0) {
                _this.setData({
                    tableList: res.data,
                })
                if(res.data.length == 1){
                    _this.selectTable({ currentTarget: { id: res.data[0].Table_ID } })
                }
            } else if (res.code == 29300) {
                wx.navigateBack({})
                co.Modal(res.msg)
            }
        })
    },
    // 点击餐桌选取
    selectTable: function (e) {
        // console.log("【获取点击的桌ID】===", e)
        var choose = this.data.value
        if(choose == '点餐'){
            wx.navigateTo({
                url: '/02local/03foodInfo/foodInfo?Guest_Num=' + this.data.num + '&Table_ID=' + e.currentTarget.id + '&value=' + this.data.value + '&Biz_ID=' + this.data.Biz_ID,
            })
        }else if( choose == '预约'){
            app.Data.tableInfo = e.currentTarget.dataset.value
            app.Data.Table_ID = e.currentTarget.id
            wx.navigateBack({})
        }

    }
})